// import Fly from 'flyio'
// const fly = new Fly()
var Fly = require("flyio/dist/npm/wx")
var fly = new Fly;



import utils from "@/utils/utils";

import {
	BASEURL,
	TIMEOUT
} from './config'

fly.config.timeout = TIMEOUT;
fly.config.baseURL = BASEURL;

fly.interceptors.request.use((request) => {
	uni.showNavigationBarLoading();
	if (request.method == "POST" || request.method === 'post') {
		request.headers["Content-Type"] = "application/json;charset=UTF-8";
		request.headers["Cache-Control"] = "no-cache";
	}

	return request;
})

fly.interceptors.response.use(
	(res) => {
		uni.hideNavigationBarLoading();
		console.log("request--res--", res)
		if (res.data.msg == "success") {
			console.log("请求成功")
			return res.data
		} else {
			console.log("请求失败")
			utils.showMessage(res.data.msg || "操作失败！");
		}


	},
	(err) => {
		//发生网络错误后会走到这里
		uni.hideNavigationBarLoading();

		if (err.status !== 200) {
			console.log("request--err--", err)
			utils.showMessage("服务器异常，请稍后重试!");
		}

	}


)

export default fly;
